"use strict";
layui.use(["okUtils", "okCountUp"], function () {
	
var data = {
	"nowMonthIncome":5000,
	"coachRank":3,
	"memberCount":10,
	"memberHistory":2000,
	"performanceChild":[{
		"commentIncome":500,
		"basicIncome":2000,
		"courseIncome":2000,
		"memberIncome":500,
		"month":"3月"
	},{
		"commentIncome":1000,
		"basicIncome":1800,
		"courseIncome":6000,
		"memberIncome":1500,
		"month":"2月"
	},{
		"commentIncome":500,
		"basicIncome":1600,
		"courseIncome":4000,
		"memberIncome":1200,
		"month":"1月"
	},{
		"commentIncome":500,
		"basicIncome":2000,
		"courseIncome":3000,
		"memberIncome":500,
		"month":"12月"
	},{
		"commentIncome":500,
		"basicIncome":1000,
		"courseIncome":5000,
		"memberIncome":1500,
		"month":"11月"
	},{
		"commentIncome":500,
		"basicIncome":1200,
		"courseIncome":7000,
		"memberIncome":500,
		"month":"10月"
	},{
		"commentIncome":500,
		"basicIncome":2000,
		"courseIncome":9000,
		"memberIncome":500,
		"month":"9月"
	},{
		"commentIncome":500,
		"basicIncome":2000,
		"courseIncome":4000,
		"memberIncome":500,
		"month":"8月"
	}]

}
	
    var countUp = layui.okCountUp;
    var okUtils = layui.okUtils;
    var $ = layui.jquery;
    okLoading.close();
    
    //在获取页面时，进行ajax访问并获取info数值赋值入data

    $.ajax({
            cache: true,
            type: "POST",
            url:"getPerformance?cid="+$("#cid").val(),
            async: false,
            error: function(request) {
                alert("失败!");
            },
            success: function(info) {
            data = info;
            }
       });   
    /**
     * 总收入、新增会员数、健身圈数、注册用户
     */
    function initMediaCont() {
        var elem_nums = $(".media-cont .num");
        elem_nums.each(function (i, j) {
            var ran = parseInt(Math.random() * 1900 + 100);
            if(i==0){
        		ran = data.nowMonthIncome;
        	}
            if(i==1){
        		ran = data.coachRank;
        	}
            if(i==2){
        		ran = data.memberCount;
        	}
            if(i==3){
        		ran = data.memberHistory;
        	}
            !new countUp({
                target: j,
                endVal: ran
            }).start();
        });
    }
    var userSourceTodayChartOption = {
        title: {show: false, text: '收入来源', subtext: '纯属虚构', x: 'center'},
        tooltip: {trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)"},
        legend: {orient: 'vertical', left: 'left', data: ['公共课奖励', '基础底薪', '课时提成', '学员提成']},
        series: [
            {
                name: '收入来源', type: 'pie', radius: '55%', center: ['50%', '60%'],
                data: [{value: data.performanceChild[0].commentIncome, name: '公共课奖励'}, {value: data.performanceChild[0].basicIncome, name: '基础底薪'}, {value: data.performanceChild[0].courseIncome, name: '课时提成'}, {value: data.performanceChild[0].memberIncome, name: '学员提成'}],
                itemStyle: {emphasis: {shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)'}}
            }
        ]
    };

    /**
     * 今日用户访问来源图表
     */
    function initUserSourceTodayChart() {
        var userSourceTodayChart = echarts.init($("#userSourceTodayChart")[0], "themez");
        userSourceTodayChart.setOption(userSourceTodayChartOption);
        okUtils.echartsResize([userSourceTodayChart]);
    }
    
/*""+data.sevenMonth[0]+"",data.sevenMouth[1], data.sevenMouth[2], data.sevenMouth[3], data.sevenMouth[4], data.sevenMouth[5], data.sevenMouth[6]*/
    var userSourceWeekChartOption = {
        title: {show: true, text: ''},
        tooltip: {trigger: 'axis', axisPointer: {type: 'cross', label: {backgroundColor: '#6a7985'}}},
        legend: {data: ['公共课奖励', '基础底薪', '课时提成', '学员提成']},
        toolbox: {show: false, feature: {saveAsImage: {}}},
        grid: {left: '3%', right: '4%', bottom: '3%', containLabel: true},
        xAxis: [{type: 'category', boundaryGap: false, data: [''+data.performanceChild[1].month+'', ''+data.performanceChild[2].month+'', ''+data.performanceChild[3].month+'', ''+data.performanceChild[4].month+'', ''+data.performanceChild[5].month+'',''+data.performanceChild[6].month+'', ''+data.performanceChild[7].month+'']}],
        yAxis: [{type: 'value', splitLine: {show: false},}],
        series: [
            {name: '公共课奖励', type: 'line', stack: '总量', smooth: true, areaStyle: {}, data: [data.performanceChild[1].commentIncome, data.performanceChild[2].commentIncome, data.performanceChild[3].commentIncome, data.performanceChild[4].commentIncome, data.performanceChild[5].commentIncome, data.performanceChild[6].commentIncome, data.performanceChild[7].commentIncome]},
            {name: '基础底薪', type: 'line', stack: '总量', smooth: true, areaStyle: {}, data: [data.performanceChild[1].basicIncome, data.performanceChild[2].basicIncome, data.performanceChild[3].basicIncome, data.performanceChild[4].basicIncome, data.performanceChild[5].basicIncome, data.performanceChild[6].basicIncome, data.performanceChild[7].basicIncome]},
            {name: '课时提成', type: 'line', stack: '总量', smooth: true, areaStyle: {}, data: [data.performanceChild[1].courseIncome, data.performanceChild[2].courseIncome, data.performanceChild[3].courseIncome, data.performanceChild[4].courseIncome, data.performanceChild[5].courseIncome, data.performanceChild[6].courseIncome, data.performanceChild[7].courseIncome]},
            {name: '学员提成', type: 'line', stack: '总量', smooth: true, areaStyle: {normal: {}}, data: [data.performanceChild[1].memberIncome, data.performanceChild[2].memberIncome, data.performanceChild[3].memberIncome, data.performanceChild[4].memberIncome, data.performanceChild[5].memberIncome, data.performanceChild[6].memberIncome, data.performanceChild[7].memberIncome]}          
        ]
    };

    /**
     * 本周用户访问来源图表
     */
    function initUserSourceWeekChart() {
        var userSourceWeekChart = echarts.init($("#userSourceWeekChart")[0], "themez");
        userSourceWeekChart.setOption(userSourceWeekChartOption);
        okUtils.echartsResize([userSourceWeekChart]);
    }

    initMediaCont();
    initUserSourceTodayChart();
    initUserSourceWeekChart();
});


